package leecode

import "sort"

func findLHS(nums []int) (result int) {
	sort.Ints(nums)
	left := 0
	for right := 0; right < len(nums); right++ {
		for left < right && nums[right]-nums[left] > 1 {
			left++
		}
		if nums[right]-nums[left] == 1 {
			result = max(result, right-left+1)
		}
	}
	return
}
